package com.kfm.jdbc.day0403;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Demo01 {

    public static void main(String[] args) {
        // 加载 students.xml 文件
        InputStream inputStream = Demo01.class.getResourceAsStream("students.xml");

        SAXReader reader = new SAXReader();

        try {
            // xml 文件转换为 Document 对象
            Document xml = reader.read(inputStream);
            System.out.println(xml.asXML());

            Element students = xml.getRootElement();
//
//            System.out.println(students.attributeCount());
//            System.out.println(students.attributeValue("title"));

            System.out.println(students);

//            List<Element> student = students.elements();
            Element student = students.element("student");
            Element name = student.element("name");
            String en = name.attributeValue("en");
            String text = name.getText();

            System.out.println(en);
            System.out.println(text);


        } catch (DocumentException e) {
            throw new RuntimeException(e);
        }


    }
}
